﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Logistics_Service.DTO;
using System.Data;


namespace Logistics_Service.DAO
{
    public class LoaiNhanVienDAO
    {
        public LoaiNhanVienDTO[] DanhSachLoaiNhanVien()
        {
            LoaiNhanVienDTO[] arr;
            string query = string.Format("select * from LoaiNhanVien");
            DataProvider provider = new DataProvider();
            DataTable dt = provider.ExecuteQuery(query);
            int n = dt.Rows.Count;
            arr = new LoaiNhanVienDTO[n];
            for (int i = 0; i < n; i++)
            {
                object lnv = GetDataFromDataRow(dt, i);
                arr[i] = (LoaiNhanVienDTO)lnv;
            }
            return arr;
        }
        protected object GetDataFromDataRow(DataTable dt, int i)
        {
            LoaiNhanVienDTO lnv = new LoaiNhanVienDTO();
            lnv.Ma = dt.Rows[i]["Ma"].ToString();
            lnv.Ten = dt.Rows[i]["TenLoai"].ToString();
            lnv.DaXoa = bool.Parse(dt.Rows[i]["DaXoa"].ToString());
            return (object)lnv;
        }
        public static LoaiNhanVienDTO Get(string ma)
        {
            string query = "select * from LoaiNhanVien where ma = '" + ma + "'";
            DataProvider provider = new DataProvider();
            LoaiNhanVienDTO lnv = new LoaiNhanVienDTO();

            DataTable dt = provider.ExecuteQuery(query);
            lnv.Ma = dt.Rows[0]["Ma"].ToString();
            lnv.Ten = dt.Rows[0]["TenLoai"].ToString();
            lnv.DaXoa = bool.Parse(dt.Rows[0]["DaXoa"].ToString());

            return lnv;
        }
    }
}